package com.shioirikukuri.mapper;

import com.shioirikukuri.entity.UserCoupon;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserCouponMapper {
	// 插入一条用户优惠券记录
	@Insert("INSERT INTO user_coupon (coupon_type_id, coupon_code, user_id, start_date, end_date, status, created_at, updated_at) " +
			"VALUES (#{couponTypeId}, #{couponCode}, #{userId}, #{startDate}, #{endDate}, #{status}, NOW(), NOW())")
	@Options(useGeneratedKeys = true, keyProperty = "id")
	int insertUserCoupon(UserCoupon userCoupon);

	// 根据ID查询用户优惠券
	@Select("SELECT * FROM user_coupon WHERE id = #{id}")
	UserCoupon selectUserCouponById(Long id);

	// 根据用户ID查询所有优惠券
	@Select("SELECT * FROM user_coupon WHERE user_id = #{userId}")
	List<UserCoupon> selectUserCouponsByUserId(Long userId);

	// 更新用户优惠券状态
	@Update("UPDATE user_coupon SET status = #{status}, updated_at = NOW() WHERE id = #{id}")
	void updateUserCouponStatus(Long id, Integer status);

	// 根据ID删除用户优惠券
	@Delete("DELETE FROM user_coupon WHERE id = #{id}")
	void deleteUserCouponById(Long id);
}
